package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

/**
 * Created by hh23485 on 2017/6/25.
 */

public class code617 {

    public static class Solution {
        public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
            return visit(t1,t2);
        }

        public TreeNode visit(TreeNode t1, TreeNode t2) {
            if(t1==null){
                return t2;
            }
            if(t2==null){
                return t1;
            }
            TreeNode treeNode = new TreeNode(t1.val+t2.val);
            treeNode.left = visit(t1.left,t2.left);
            treeNode.right = visit(t1.right,t2.right);
            return treeNode;
        }
    }
    public static void main(String[] args){

    }
}
